<template>
  <div class="bottom-bar">
    <label class="mdui-checkbox checkbutton"><input type="checkbox" v-model="isSelectAll" @click="checkclick()" /><i
        class="mdui-checkbox-icon"></i>全选</label>
    <div class="price">合计：{{totalPrice}}</div>
    <div class="calculate"><button
        class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-theme-accent">去计算：{{checkLength}}</button>
    </div>
  </div>
</template>

<style scoped>
  .bottom-bar {
    height: 40px;
    position: relative;
    background: #eee;
    bottom: -89%;
    display: flex;
    align-items: center;
  }

  .checkbutton {
    width: 25%;
  }

  .price {
    width: 50%;
  }

  .calculate {
    width: 25%;
    display: flex;
    justify-content: flex-end;
  }
</style>

<script>
  import { mapGetters } from 'vuex'

  export default {
    name: '',
    //传参：父传子，写法：["形参1"[,"形参2"]]
    props: {

    },
    created() {

    },
    mounted() {

    },
    data() {
      return {

      }
    },
    computed: {
      ...mapGetters([
        'cartLength',
        'cartList',
      ]),
      totalPrice() {
        return '￥' + this.$store.state.cartList.filter(item => {
          return item.checked
        }).reduce((preValue, item) => {
          return preValue + item.price * item.count;
        }, 0).toFixed(2)

      },
      checkLength() {
        return this.$store.state.cartList.filter(item => item.checked).length
      },
      isSelectAll() {
        if (this.cartList.length === 0) {
          return false
        }
        return !(this.cartList.find(item => !item.checked))
        //return !(this.cartList.filter(item => !item.checked).length)
      },
    },
    methods: {
      checkclick() {
        if (this.isSelectAll) {
          this.cartList.forEach(item => item.checked = false)
        } else {
          this.cartList.forEach(item => item.checked = true)
        }
      },

    },
    mixins: [],
    components: {

    },
  }
</script>